//
//  GWAccount.m
//  新浪微博
//
//  Created by qianfeng on 16/1/13.
//  Copyright (c) 2016年 高炜. All rights reserved.
//

#import "GWAccount.h"

@implementation GWAccount
+(GWAccount *)accountWithDict:(NSDictionary *)dict
{
    
    GWAccount *account =[[self alloc]init];
    account.access_token =dict[@"access_token"];
    account.expires_in =dict[@"expires_in"];
    account.uid =dict[@"uid"];
    NSDate *now =[[NSDate date]dateByAddingTimeInterval:[account.expires_in doubleValue]];
    account.expires_time =now;
    return account;
}
-(id)initWithCoder:(NSCoder *)aDecoder
{
    if (self =[super init]) {
        self.access_token  =[aDecoder decodeObjectForKey:@"access_token"];
        self.expires_in  =[aDecoder decodeObjectForKey:@"expires_in"];
        self.uid  =[aDecoder decodeObjectForKey:@"uid"];
        self.expires_time  =[aDecoder decodeObjectForKey:@"expires_time"];
        self.username =[aDecoder decodeObjectForKey:@"username"];
    }
    return self;
}
-(void)encodeWithCoder:(NSCoder *)enCoder
{
    [enCoder encodeObject:self.access_token forKey:@"access_token"];
    [enCoder encodeObject:self.expires_in forKey:@"expires_in"];
    [enCoder encodeObject:self.uid forKey:@"uid"];
    [enCoder encodeObject:self.expires_time forKey:@"expires_time"];
    [enCoder encodeObject:self.username forKey:@"username"];
}
@end
